package com.lyf.controller;

import com.lyf.entity.Payment;
import com.lyf.entity.ResponseResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @AUTHOR LYF
 * @DATE 2022/2/5
 * @VERSION 1.0
 * @DESC
 */
@RestController
public class OrderController {
    @Resource
    RestTemplate restTemplate;
    final String PAYMENT_URL = "http://PAYMENT-SERVICE";//"http://localhost:8001";

    @GetMapping("/consumer/payment/create")
    ResponseResult<Payment> create(Payment payment){
        return restTemplate.postForObject(PAYMENT_URL+"/payment/create",payment,ResponseResult.class);
    }

    @GetMapping("/consumer/payment/get/{id}")
    ResponseResult<Payment> getPaymentById(@PathVariable(name = "id") Long id){
        return restTemplate.getForObject(PAYMENT_URL+"/payment/get/"+id,ResponseResult.class);
    }

}
